//发送Ajax请求
// 封装功能函数
import config from './config.js'
export default (url, data={}, method="GET")=>{
  return new Promise((resolve,reject)=>{
    //1.new Promises 初始化 Promises 实例的状态为 pending
   wx.request({
     url: config.host + url,
     data,
     method,
     header:{
      cookie: wx.getStorageSync('cookies')
      ?wx.getStorageSync('cookies')
      .find(item => item.indexOf('MUSIC_U') !== -1):''
     },
     success:(res)=>{
      //  console.log(res);
      if(data.isLogin){//登录请求
        wx.setStorage({
          key:'cookies',
          data:res.cookies
        })
      }
       resolve(res.data)
     },
     fail:(err)=>{
      //console.log('失败',err);
      reject(err)
     }
   })
  })
}